<%@ page language="java" import="java.util.*" pageEncoding="UTF-8" %>
<% String path=request.getContextPath(); String basePath=request.getScheme()+ "://" + request.getServerName() + ":" + request.getServerPort() + path+ "/"; %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" >
<html  xmlns="http://www.w3.org/1999/xhtml">
<head>
    <base href="<%=basePath%>">
    <title>佣金确认单管理-保单管理</title>
    <%@ include file="/WEB-INF/jsp/common/common.jsp" %>
    <script src="<%=path%>/js/jquery.divbox.js" type="text/javascript"></script>
    <script src="js/json2.js" type="text/javascript"></script>
    <script type="text/javascript">

        var applyId="${applyId}";
        var insurerId="${insurerId}";
        var state="${state}";

        $(document).ready(function() {
            //确认单信息置灰
            $("#insurerId").attr("disabled",true);
            $("#insurerId").css("background-color","#CCC");
            $("#insurerId").val("${insurerId}");
            $("#id").attr("disabled",true);
            $("#id").css("background-color","#CCC");
            $("#id").val("${applyId}");
            $("#state").attr("disabled",true);
            $("#state").css("background-color","#CCC");
            $("#state").val("${state}");

            queryPolicyPageByApplyId(1)
        });

        function queryPolicyPageByApplyId(pageIndex) {
            $.openLoading();
            $.ajax({
                url : "<%=path%>/commission/queryPolicyPageByApplyId",
                type : 'POST',
                async : true,
                data: {
                    current:pageIndex,
                    size:10,
                    applyId:applyId
                },
                dataType:'json',
                success:function(page){
                    $.closeLoading();
                    if($.validate(page)){
                        return;
                    }
                    var lastbutton = "<a href='javascript:void(0)' onClick='toCheck(this);return false'>核准</a>";
                    var tableContent = creatTable("id,project,company,product,policyNo,precent,title,rate,premium,percentage,commission,result",page,lastbutton);

                    var tableObj = $("#policyTable");
                    tableObj.find("tbody").remove();
                    tableObj.append(tableContent);
                    var strPage = creatChannelPage(pageIndex,6,page.maxPage,"112");
                    var pageDIV = $("#policyPageDiv");
                    pageDIV[0].innerHTML="";
                    pageDIV.append(strPage);
                }
            });
        }

        //--------------------------------核准-------------------------------------------------------

        var policyId;

        function toCheck(obj) {
            var detailTr = $(obj).parent('td').parent('tr')[0];
            policyId = detailTr.childNodes[0].innerHTML;//业务编号

            $.ajax({
                url: "<%=path%>/commission/queryToCheck",
                type: 'GET',
                async: false,
                dataType: 'json',
                data: {
                    policyId: policyId
                },
                success:function (data) {
                    $("#result").val(data.result);
                    $("#description").val(data.description);
                }
            });
            $('#checkPolicyDiv').OpenDiv();
        }

        function closeCheckPolicy() {
            $("#result").val('');
            $("#description").val('');
            $('#checkPolicyDiv').CloseDiv();
        }

        function saveCheckPolicy() {

            var result = $('#result').val() + "";
            let numberReg = /^\d+$|^\d+[.]?\d+$/
            if (result !== '') {
                if (!numberReg.test(result)) {
                    $.closeLoading();
                    $.message("error","请输入数字");
                    return;
                }
            }

            $.openLoading();
            var result = $("#result").val();
            var description = $("#description").val();
            $.ajax({
                url: "<%=path%>/commission/saveCheckPolicy",
                type: 'POST',
                async: false,
                dataType: 'json',
                data: {
                    id: policyId,
                    result:result,
                    description:description
                },
                success:function (data) {
                    $.closeLoading();
                    $.message(data.result,data.message);
                    window.setTimeout(function () {
                        $('#checkPolicyDiv').CloseDiv();
                    },1000)
                }
            });
        }

    </script>
</head>
<body>
    <div class="current">
        <table class="current_table_1">
            <tbody>
            <tr class="f2">
                <td>
                    <img src="./images/current_1.jpg">
                </td>
                <td class="current_table_1_td">
                    <img src="images/current_1.png">&nbsp;您现在的位置：&nbsp;
                    <span style=" color:#136bab; ">中建英大
                        <span style="padding:0 5px; font-weight:bold; line-height:28px;">&gt;</span>佣金确认单管理
                    </span>
                </td>
                <td><img src="./images/current_3.jpg"></td>
            </tr>
            </tbody>
        </table>
    </div>

    <%--查询条件及结果表单--%>
    <table border="1" class="table_02" style="height:150px">
        <tr height="50px">
            <td colspan="2" align="center">
                <form method="post" id="queryPolicyListForm">
                    <table border="0" style="margin: 12px auto;">
                        <tr>
                            <td style="padding-left:40px; border: 0;text-align: right" nowrap="nowrap">保险公司编号：</td>
                            <td style="border: 0;text-align: left;padding-right: 70px">
                                <input name="insurerId" id="insurerId" class="input_text" style="width:130px;"/>
                            </td>

                            <td style="padding-left:40px;border: 0;text-align: right" nowrap="nowrap">确认单号：</td>
                            <td style="border: 0;text-align: left;padding-right: 70px">
                                <input name="id" id="id" class="input_text" style="width:130px;"/>
                            </td>

                            <td style="border: 0;text-align: right;" nowrap="nowrap">状态：</td>
                            <td style="border: 0;text-align: left;padding-right: 70px">
                                <input name="state" id="state" class="input_text" style="width:130px;"/>
                            </td>
                        </tr>
                    </table>
                </form>
            </td>
        </tr>
        <tr>
            <td>
                <tr>
                    <td style="text-align:right" >
                         <input id="goBack" type="button" class="input_button_4" value="返回" style="margin-right: 24px"
                         onclick="window.history.go(-1);"/>
                    </td>
                </tr>
            </td>
        </tr>
        <tr>
            <td valign="top">
                <div id="policyDiv" style="width:98%;margin:5px" >
                    <table class="table_02" id="policyTable">
                        <thead>
                            <tr>
                                <th style="width:10%" nowrap="nowrap">业务编号</th>
                                <th style="width:10%" nowrap="nowrap">项目名称</th>
                                <th style="width:5%" nowrap="nowrap">投保人</th>
                                <th style="width:5%" nowrap="nowrap">险种</th>
                                <th style="width:10%" nowrap="nowrap">保单号</th>
                                <th style="width:5%" nowrap="nowrap">共保占比(%)</th>
                                <th style="width:5%" nowrap="nowrap">佣金期数</th>
                                <th style="width:5%" nowrap="nowrap">分期比例(%)</th>
                                <th style="width:5%" nowrap="nowrap">含税保费(元)</th>
                                <th style="width:5%" nowrap="nowrap">佣金比例(%)</th>
                                <th style="width:5%" nowrap="nowrap">含税佣金(元)</th>
                                <th style="width:5%" nowrap="nowrap">核定佣金金额(元)</th>
                                <th style="width:5%" nowrap="nowrap">核准页</th>
                            </tr>
                        </thead>
                        <tbody>
                        </tbody>
                    </table>
                    <%--分页--%>
                    <div id="policyPageDiv"  class="page"></div>
                </div>
            </td>
        </tr>
    </table>

    <!--核准 DIV 默认隐藏-->
    <div id="checkPolicyDiv"  style="display:none;width:500px;height: 330px">
        <input type="hidden" id="row_num" name="row_num" value="0"/>
        <div class="table_title_div">
            <table class="table_title" style='width:100%;'>
                <tr>
                    <td width="10%"></td>
                    <td width="80%" id="interfaceName"></td>
                    <td width="10%" align="right"><img src="<%=path%>/images/closedown.gif" alt="关闭"  onclick="closeCheckPolicy()"/></td>
                </tr>
            </table>
        </div>

        <form id="checkPolicyForm" action="save.jhtml" method="post" enctype="multipart/form-data">
            <table class="table_02" id="uploadDivTable" align="center" >
                <tbody>
                <%--<tr style="height: 100px">
                    <td>
                        <input id="uploadFile" name="uploadFile" type='file' size='20'/>
                    </td>
                </tr>--%>
                <tr style="height: 50px">
                    <td>
                        核定佣金金额(元):<input type="text" id="result" name="result">
                    </td>
                </tr>
                <tr style="height: 200px">
                    <td colspan="2">
                        修正说明:<textarea id="description" name="description" rows="6" cols="10" style="height: 150px;width: 400px"></textarea>
                    </td>
                </tr>
                </tbody>
            </table>
            <div align="center">
                <input class="input_button_3" name="" type="button" onclick="saveCheckPolicy()" value="保存">
                <input class="input_button_3" name="" type="button" onclick="closeCheckPolicy()" value="取消">
            </div>
        </form>
    </div>

</body>
</html>
